home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-07 | 4.0 KB | 132 lines | [TEXT/MPS ] |
- (*
- CTBNewConnection [tool[,inBufSz[,outBfSz]]] -- Make a new connection. If one is open, dispose of it.
- The tool parameter is the initial tool name to use. The inBufSz and outBufSz parameters are the
- sizes of the input and output buffers to allocate.
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- pascal -w CTBNewConnection.p
- link -m ENTRYPOINT -o HyperCommands -rt XCMD=2752 -sn Main=CTBNewConnection ∂
- CTBNewConnection.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
-
- © Copyright 1990 by Apple Computer, Inc.
-
- Initial coding 2/90 by Harry R. Chesley.
- *)
-
- {$R-}
-
- {$S CTBNewConnection } { Segment name must be the same as the command name. }
-
- unit DummyUnit;
-
- interface
-
- uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- implementation
-
- procedure CTBNewConnection(paramPtr: XCmdPtr); forward;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- begin
- CTBNewConnection(paramPtr);
- end;
-
- procedure CTBNewConnection(paramPtr: XCmdPtr);
-
- {$I CTBUtil.inc}
-
- var i, j: integer;
- szs: CMBufferSizes;
- szsIndx: CMBufFields;
- toolName: Str255;
- procID: integer;
- theBuf: InputBufferHandle;
- cHand: ConnHandle;
-
- procedure Fail(errMsg: Str255); { set theResult and quit }
- begin
- paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
- exit(CTBNewConnection);
- end;
-
- begin
- { Verify the number of parameters. }
- if paramPtr^.paramCount > 3 then Fail('Invalid parameter count');
-
- { Check that the Comm Toolbox is present and ready. }
- CTBReady;
-
- { Get the buffer sizes. }
- for szsIndx := cmDataIn to cmRsrvOut do szs[szsIndx] := 0;
- if ParmPresent(2) then szs[cmDataIn] := GetLongParm(1);
- if ParmPresent(3) then szs[cmDataOut] := GetLongParm(2);
-
- { If there's already a connection allocated, get rid of it. }
- if Globals^^.connHand <> nil then
- begin
- { Dispose of the connection itself. }
- theBuf := InputBufferHandle(CMGetUserData(Globals^^.connHand));
- CMDispose(Globals^^.connHand);
- { Get rid of the input buffer. }
- DisposHandle(Handle(theBuf));
- { Remove it from the outstanding tools list. }
- j := 1;
- for i := 1 to Globals^^.allToolsSize do
- if Globals^^.allTools[i].cHand <> Globals^^.connHand then
- begin
- Globals^^.allTools[j] := Globals^^.allTools[i];
- j := j+1;
- end;
- Globals^^.allToolsSize := Globals^^.allToolsSize-1;
- SetHandleSize(Handle(Globals),sizeof(OurGlobalType)-sizeof(ToolArray)+
- Globals^^.allToolsSize*sizeof(OneToolType));
- Globals^^.connHand := nil;
- end;
-
- { Find the proc ID. }
- if ParmPresent(1) then GetStrParm(1,toolName)
- else toolName := 'Serial Tool';
- { Get the ID. }
- procID := CMGetProcID(toolName);
- if procID = -1 then
- begin
- { If we can't get what we want, try to get what we need. }
- if CRMGetIndToolName(ClassCM,1,toolName) <> noErr then procID := -1
- else procID := CMGetProcID(toolName);
- { If there's not tools at all, fail. }
- if procID = -1 then Fail('Cannot find a default tool');
- end;
-
- { Allocate an input buffer. }
- theBuf := InputBufferHandle(NewHandle(sizeof(InputBufferType)));
- if theBuf = nil then Fail('Could not create buffer');
- MoveHHi(Handle(theBuf));
- HLock(Handle(theBuf));
- theBuf^^.amountLeft := 0;
- theBuf^^.timeOut := -1;
- theBuf^^.termString := nil;
- { Create the new connection handle. }
- cHand := CMNew(procID,cmData+cmDataClean+cmNoMenus+cmQuiet,szs,0,ord4(theBuf));
- { Did we make it? }
- if cHand = nil then
- begin
- DisposHandle(Handle(theBuf));
- Fail('Could not create new connection record');
- end;
- { Save it. }
- Globals^^.connHand := cHand;
- { Add it to the outstanding tools list. }
- Globals^^.allToolsSize := Globals^^.allToolsSize+1;
- SetHandleSize(Handle(Globals),sizeof(OurGlobalType)-sizeof(ToolArray)+
- Globals^^.allToolsSize*sizeof(OneToolType));
- Globals^^.allTools[Globals^^.allToolsSize].tType := connectionTool;
- Globals^^.allTools[Globals^^.allToolsSize].cHand := Globals^^.connHand;
- end;
-
- end.
-